package com.turing.usdtpay.mvp.dialog;

import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.turing.usdtpay.R;
import com.turing.usdtpay.base.BaseDialog;
import com.turing.usdtpay.utils.ScreenUtils;

/**
 * @作者：JAY
 * @创建时间：2019/10/15 20:32
 * @描述：
 **/
public class ManageDialog extends BaseDialog<ManageDialog> {
    private ImageView mBack;
    private RelativeLayout mTodayLayout,mAddLayout;
    private TextView mTodayTv,mAddTv;
    private ImageView mTodayIv,mAddIv;
    private OnClickListener mOnClickListener;
    private int mType = 1;
    public ManageDialog(Context context) {
        super(context);
    }

    public ManageDialog(Context context, boolean isPopupStyle) {
        super(context, isPopupStyle);
    }

    public ManageDialog(Context context, int theme) {
        super(context, theme);
    }

    public void setOnClickListener(OnClickListener mOnClickListener) {
        this.mOnClickListener = mOnClickListener;
    }

    @Override
    public View onCreateView() {
        View view = LayoutInflater.from(mContext).inflate(R.layout.dialog_manage, null);
        initView(view);
        return view;
    }



    private void initView(View view) {
        mBack = (ImageView) view.findViewById(R.id.left_iv);
        mTodayLayout = (RelativeLayout) view.findViewById(R.id.today_layout);
        mAddLayout = (RelativeLayout) view.findViewById(R.id.add_layout);
        mTodayTv = (TextView) view.findViewById(R.id.tv_today);
        mAddTv = (TextView) view.findViewById(R.id.tv_add);
        mTodayIv = (ImageView) view.findViewById(R.id.iv_today);
        mAddIv = (ImageView) view.findViewById(R.id.iv_add);
        mBack.setOnClickListener(this);
        mTodayLayout.setOnClickListener(this);
        mAddLayout.setOnClickListener(this);
    }


    @Override
    public void setUiBeforeShow() {

    }

    @Override
    public void onClick(View v) {
        if (v.getId() == mBack.getId()){
            dismiss();
        }else if (v.getId() == mTodayLayout.getId()){
            mTodayTv.setTextColor(mContext.getResources().getColor(R.color.colorBlue));
            mTodayIv.setVisibility(View.VISIBLE);
            mAddTv.setTextColor(mContext.getResources().getColor(R.color.colorBlack));
            mAddIv.setVisibility(View.GONE);
            mType = 0;
        }else if (v.getId() == mAddLayout.getId()){
            mTodayTv.setTextColor(mContext.getResources().getColor(R.color.colorBlack));
            mTodayIv.setVisibility(View.GONE);
            mAddTv.setTextColor(mContext.getResources().getColor(R.color.colorBlue));
            mAddIv.setVisibility(View.VISIBLE);
            mType = 1;
        }
    }

    public void setType(int type){
        mType = type;
        if (type == 0){
            mTodayTv.setTextColor(mContext.getResources().getColor(R.color.colorBlue));
            mTodayIv.setVisibility(View.VISIBLE);
            mAddTv.setTextColor(mContext.getResources().getColor(R.color.colorBlack));
            mAddIv.setVisibility(View.GONE);
        }else {
            mTodayTv.setTextColor(mContext.getResources().getColor(R.color.colorBlack));
            mTodayIv.setVisibility(View.GONE);
            mAddTv.setTextColor(mContext.getResources().getColor(R.color.colorBlue));
            mAddIv.setVisibility(View.VISIBLE);
        }
    }

    @Override
    public void show() {
        super.show();
        WindowManager.LayoutParams layoutParams = getWindow().getAttributes();
        layoutParams.width = ScreenUtils.getScreenWidth(mContext);
        getWindow().setGravity(Gravity.TOP);
        getWindow().setAttributes(layoutParams);
    }

    public interface OnClickListener{
        public void onSelection(int type);
    }

    @Override
    public void dismiss() {
        if (mOnClickListener != null){
            mOnClickListener.onSelection(mType);
        }
        super.dismiss();
    }
}
